package com.changyue.bleHelper.Req;

import android.util.Log;

import com.changyue.temp.BuildConfig;

public class BLEReq {
    public byte[] req = null;

    protected void checkout() {
        Integer sum = 0;
        for (int i = 0 ; i < req.length - 2; i++) {
            sum = sum + (int)(req[i] & 0xff);
        }

        Integer code = sum & 0xff;
        int lastNum = req.length - 1;
        req[lastNum] = code.byteValue();
    }

    public byte[] getReq() {
        checkout();
        if (BuildConfig.DEBUG) {
            StringBuilder stringBuilder = new StringBuilder("");
            if (req == null || req.length <= 0) {
                return null;
            }
            for (int i = 0; i < req.length; i++) {
                int v = req[i] & 0xFF;
                String hv = Integer.toHexString(v).toUpperCase();
                if (hv.length() < 2) {
                    hv = "0" + hv;
                }
                stringBuilder.append("0x" + hv + " ");
            }
            Log.d("BLEReq === ", stringBuilder.toString());
        }
        return req;
    }
}
